<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>MyName</title>
    <script type="text/javascript">
        //静态注册
        function funOnclick() {
            alert("静态注册")
        }

        window.onclick = function () {
            let id = document.getElementById("12");
            id.onclick = function () {
                alert("动态注册")
            }
        }

    </script>
</head>
<body>
    <button onclick="funOnclick()">按钮1</button>
    <br>
    <button id="12">按钮2</button>
    <a href="https://www.baidu.com" target="_blank">百度</a>
</body>
</html>